package com.sn.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sn.core.component.page.Pagination;
import com.sn.core.http.CommRequest;
import com.sn.model.Customer;
import com.sn.model.VipUser;
import com.sn.model.req.CustomerReq;
import com.sn.model.req.VipUserReq;
import com.sn.model.vo.CustomerVo;
import com.sn.model.vo.VipUserVo;
import com.sn.service.UserService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/6/20.
 */
@RequestMapping(value = "customer")
@Controller
@EnableAutoConfiguration
public class UserController extends BaseController {
    @Resource
    private UserService userService;

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/addCustomer")
    @ResponseBody
    @Transactional
    public Object addCustomer(@RequestBody CommRequest<Customer> userQueryCommRequest) {
        userService.addCustomer(userQueryCommRequest.getData());
        return responseJson(null);
    }


    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/queryVipSearchList")
    @ResponseBody
    @Transactional
    public Object queryVipSearchList(@RequestBody CommRequest<CustomerReq> userQueryCommRequest) {
       List<Customer> vos= userService.queryVipSearchList(userQueryCommRequest.getData().getTruename(),userQueryCommRequest.getData().getUsertype());
        return responseJson(vos);
    }


    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/updateCustomer")
    @ResponseBody
    @Transactional
    public Object updateCustomer(@RequestBody CommRequest<Customer> userQueryCommRequest) {
        userService.updateCustomer(userQueryCommRequest.getData());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/deleteCustomer")
    @ResponseBody
    @Transactional
    public Object deleteCustomer(@RequestBody CommRequest<Customer> userQueryCommRequest) {
        userService.deleteCustomer(userQueryCommRequest.getData().getCid());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/queryCustomer")
    @ResponseBody
    @Transactional
    public Object queryCustomer(@RequestBody CommRequest<CustomerReq> userQueryCommRequest) {

       Object o= userService.queryCustomer(userQueryCommRequest.getData());
        return responseJson(o);
    }
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/login")
    @ResponseBody
    @Transactional
    public Object login(@RequestBody CommRequest<CustomerReq> userQueryCommRequest) {
        CustomerVo vo=userService.login(userQueryCommRequest.getData());
        return responseJson(vo);
    }
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/updatePwd")
    @ResponseBody
    @Transactional
    public Object updatePassword(@RequestBody CommRequest<CustomerReq> userQueryCommRequest) {
        userService.updatePwd(userQueryCommRequest.getData());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/customerDetail")
    @ResponseBody
    @Transactional
    public Object customerDetail(@RequestBody CommRequest<CustomerReq> userQueryCommRequest) {
       CustomerVo vo= userService.detail(userQueryCommRequest.getData().getCid());
        return responseJson(vo);
    }








}
